var integralTermCompanyTree = new Object();

//初始化
integralTermCompanyTree.init = function () {
    integralTermCompanyTree.initTree();
}

integralTermCompanyTree.tree_options = {
    id: 'integral_term_company_tree',
    url: appPath + '/admin/integralProgramme/integralTermCompanyTree',
    setting: {
        check: {
            enable: true,
            chkStyle:"radio",
            radioType :  "all"
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        view: {
            dblClickExpand: false,
            fontCss: getFontCss
        },
        callback: {
            onCheck: function (e,treeId, treeNode) {
                integralTermCompanyTree.showOrHide();
            },
            onClick: function (e,treeId, treeNode, clickFlag) {
                integralTermCompanyTree.business_zTree.checkNode(treeNode, !treeNode.checked, true);
                integralTermCompanyTree.showOrHide();
            }
        }
    }
};

//初始化树
integralTermCompanyTree.initTree = function(){
    $.ajax({
        url: integralTermCompanyTree.tree_options.url,
        async: false,
        type: 'post',
        data: {},
        success: function(data){
            integralTermCompanyTree.tree_options.zNodes = eval(data.result);
            // 加载树
            integralTermCompanyTree.business_zTree = $.fn.zTree.init($("#integral_term_company_tree"), integralTermCompanyTree.tree_options.setting, integralTermCompanyTree.tree_options.zNodes);

        }
    });
};

integralTermCompanyTree.showOrHide = function(){
    var nodes = integralTermCompanyTree.business_zTree.getCheckedNodes(true);
    for(var i = 0; i < nodes.length; i++){
        var n = nodes[i];
        $(".nav").hide();
        $("#div_integral_rule_"+n.id).show();
    }
}

//搜索高亮
function getFontCss(treeId, treeNode){
    return (!!treeNode.highlight)?{'color': "#A60000", 'font-weight':"bold"}:{'color': "#333", 'font-weight':"normal"};
}